/*
 * Class
 * SingleParameter
 */
package pl.abstractvoid.datamodel.parameters;

import java.io.Serializable;
import pl.abstractvoid.languages.LanguageProvider;

/**
 * Represents a single parameter of a probability distribution.
 * <p>
 * As a 'single parameter' we consider a parameter that is a scalar value like
 * sigma in the normal distribution and occures only once in the set of
 * parameters of the distribution.
 *
 * @author Wojciech Szałapski
 * @author Ivo Zieliński
 */
public class SingleParameter implements Serializable {

    /**
     * The serial number for serialization and deserialization with different 
     * versions of the application.
     */
    static final long serialVersionUID = 1L;
    /**
     * Name of the parameter for access from R scripts.
     */
    private final String parameterName;

    /**
     * Name of the parameter for user interface.
     */
    private String visibleParameterName;

    /**
     * Value of the parameter.
     */
    private double parameterValue;

    /**
     * Flag representing if the actual value of the parameter should be rounded
     * down to the nearest integer value.
     */
    private boolean isInteger = false;

    /**
     * Constructor initializing the parameter's names.
     * <p>
     * The default value of the parameter is always 0.
     *
     * @param parameterName Name of the parameter that is used to access it
     * inside R scripts.
     */
    public SingleParameter(String parameterName) {
        this.parameterName = parameterName;
        this.parameterValue = 0;
    }

    /**
     * Returns the name of the parameter for access by R connector.
     *
     * @return Name of the parameter that is used by R connector.
     */
    public String getParameterName() {
        return parameterName;
    }

    /**
     * Returns the name of the parameter for user interface.
     *
     * @return Name of the parameter that is visible in user interface.
     */
    public String getVisibleParameterName() {
        return LanguageProvider.getInstance().getDistributionString(parameterName);
    }

    /**
     * Returns the value of the parameter.
     *
     * @return Current value of the parameter.
     */
    public double getParameterValue() {
        return parameterValue;
    }

    /**
     * Sets the value of the parameter.
     *
     * @param parameterValue New value of the parameter.
     */
    public void setParameterValue(double parameterValue) {
        this.parameterValue = parameterValue;
    }

    /**
     * Returns the hash code of the parameter.
     * 
     * @return Hash code of the parameter's value.
     */
    public double getHash() {
        return parameterValue * 13;
    }

    /**
     * Returns if the parameter's value should be treated as integer.
     *
     * @return Flag representing if the parameter's value should be rounded down
     * to the nearest integer number.
     */
    public boolean isIsInteger() {
        return isInteger;
    }

    /**
     * Sets the parameter as representing an integer value.
     */
    public void setInteger() {
        isInteger = true;
    }
}
